package org.ipower.platform.cfg;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
/*
 * 系统模块定义集合。
 * */
public class ModuleSystemDefineCollection implements Collection<ModuleSystemDefine>,Comparator<ModuleSystemDefine>, Serializable {
	//序列化标识。
	private static final long serialVersionUID = -6403589179557132391L;
	private List<ModuleSystemDefine> list= null;
	/*
	 * 构造函数。
	 * */
	public ModuleSystemDefineCollection(){
		this.list = new ArrayList<ModuleSystemDefine>();
	}
	/*
	 * 构造函数。
	 * */
	public ModuleSystemDefineCollection(ModuleSystemDefine define){
		this();
		if(define != null)
			this.add(define);
	}
	@Override
	public int compare(ModuleSystemDefine x, ModuleSystemDefine y) {
		if(x.getSystemID() == y.getSystemID())
			return 0;
		return x.getSystemID().compareToIgnoreCase(y.getSystemID());
	}
	/*
	 * 
	 * */
	public ModuleSystemDefine item(int index){
		if(index < 0 || index > this.size() - 1)
			return null;
		ModuleSystemDefine[] items = (ModuleSystemDefine[]) this.list.toArray();
		if(items != null && items.length > 0){
			 return items[index];
		}
		return null;
	}
	/*
	 * 
	 * */
	public ModuleSystemDefine item(String systemID){
		if(systemID != null && this.size() >0){
			for(ModuleSystemDefine item : this){
				boolean result = item.getSystemID().equalsIgnoreCase(systemID);
				if (result){
					return item; 
				}
			}
		}
		 return null;
	}
	@Override
	public int size() {
		 return this.list.size();
	}
	@Override
	public boolean isEmpty() {
		return this.list.isEmpty();
	}
	@Override
	public boolean contains(Object o) {
		return this.list.contains(o);
	}
	@Override
	public Iterator<ModuleSystemDefine> iterator() {
		Collections.sort(this.list, this);
		return this.list.iterator();
	}
	@Override
	public Object[] toArray() {
		return this.list.toArray();
	}
	@Override
	public <T> T[] toArray(T[] a) {
		return this.list.toArray(a);
	}
	@Override
	public boolean add(ModuleSystemDefine e) {
		if(e == null) 
			return false;
		return this.list.add(e);
	}
	@Override
	public boolean remove(Object o) {
		if(o == null)
			return false;
		return this.list.remove(o);
	}
	@Override
	public boolean containsAll(Collection<?> c) {
		if(c == null || c.size() == 0)
			return false;
		return this.list.containsAll(c);
	}
	@Override
	public boolean addAll(Collection<? extends ModuleSystemDefine> c) {
		if(c == null || c.size()  == 0)
			return false;
		return this.list.addAll(c);
	}
	@Override
	public boolean removeAll(Collection<?> c) {
		if(c == null || c.size() == 0)
			return false;
		return this.list.removeAll(c);
	}
	@Override
	public boolean retainAll(Collection<?> c) {
		if(c == null || c.size() == 0)
			return false;
		return this.list.retainAll(c);
	}
	@Override
	public void clear() {
		this.list.clear();
	}
}
